// pages/gongjv/pages/star/star.js
import api from '../../../../componets/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
// aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces

    navList: [{ id:0, name: '白羊座', type:'aries'},
              { id:1, name: '金牛座' ,type:'taurus'},
              { id:2, name: '双子座' ,type:'gemini'},
              { id:3, name: '巨蟹座' ,type:'cancer'},
              { id:4, name: '狮子座' ,type:'leo'},
              { id:5, name: '处女座' ,type:'virgo'},
              { id: 6, name:'天枰座' ,type:'libra'},
              { id: 7, name:'天蝎座' ,type:'scorpio'},
              { id: 8, name:'射手座' ,type:'sagittarius'},
              { id: 9, name:'摩羯座' ,type:'capricorn'},
              { id: 10, name:'水瓶座',type:'aquarius' },
              { id: 11, name:'双鱼座',type:'pisces' }
  ],
  currentTab:0,
  type:'aries',
  time:'month',
  items: [
    {value: 'today', name: '今日',checked: 'true'},
    {value: 'nextday', name: '明日'},
    {value: 'week', name: '本周'},
    {value: 'month', name: '本月'},
  ],
  starInfo:{},
  imgUrl:''
  },
    // 返回工具页
    comback:function(){
      wx.switchTab({
        url: '/pages/gongjv/gongjv', // 要跳转的页面路径
      });
    },
  // 选择星座
  navbarTap: function (e) {
  for(let i=0;i<this.data.navList.length;i++){
    if(this.data.navList[i].id==e.currentTarget.id){
      this.setData({
        type:this.data.navList[i].type,
        currentTab: e.currentTarget.id
      })
    }
  }
  this.getStar(this.data.type,this.data.time)
  },
// 选择时间
  radioChange(e) {
    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    this.setData({
      time:e.detail.value
    })
    this.getStar(this.data.type,this.data.time)
  },
// 获取运势
getStar:function(type,time){
  api.get(`https://v2.api-m.com/api/horoscope`,{type:type,time:time})
  .then(res=>{
    this.setData({
      starInfo:res.data.data,
      imgUrl:`/icon/${res.data.data.name}.png`
    })
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getStar(this.data.type,this.data.time)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getStar(this.data.type,this.data.time)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})